package com.junxonline.plat.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * @ClassName: CorsConfig
 * @Description: 管理平台全局跨域配置类
 * @author JunX
 */

@Configuration
public class CorsConfig {

    /**
     * 跨域配置
     */
    @Bean
    public WebMvcConfigurer corsConfigurer() {
        WebMvcConfigurer config = new WebMvcConfigurer() {
            @Override
            public void addCorsMappings(CorsRegistry registry) {
                registry.addMapping("/**")
                        // 允许跨域的客户端域名
                        .allowedOrigins("http://localhost:8010", "http://www.junxtec.com")
                        // 允许跨域的请求类型
                        .allowedMethods("GET", "POST")
                        // 禁止cookie
                        .allowCredentials(true)
                        // 跨域预检测有效期：3600毫秒 / 1分钟
                        .maxAge(3600);
            }
        };
        return config;
    }

}
